﻿SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[bhp_NemoGroupIdentyficatorSet]
	@Id				INT,
	@Ident			NVARCHAR(200)
AS
BEGIN
	
	DECLARE
		@Sql		NVARCHAR(MAX)

	IF(OBJECT_ID('TR213') IS NULL)
		SET @Sql = 'CREATE '
	ELSE
		SET @Sql = 'ALTER '
	
	SET @Sql = @Sql + 'FUNCTION [dbo].[TR' + CAST(@Id AS NVARCHAR(10)) + '] (@Id INT)
RETURNS NVARCHAR
AS
BEGIN

	DECLARE
		@Ident	NVARCHAR(200)

	SELECT
		@Ident = ' + @Ident + '
	FROM
		T' + CAST(@Id AS NVARCHAR(10)) + '
	WHERE
		idx = @Id

	RETURN @Ident

END
'
	PRINT @Sql
	EXEC sp_executesql @Sql
	
END



